package cn.lfy.studentmanager.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.lfy.studentmanager.dao.AcademyDao;
import cn.lfy.studentmanager.dao.DepartmentDao;
import cn.lfy.studentmanager.domain.Academy;
import cn.lfy.studentmanager.domain.Department;
import cn.lfy.studentmanager.service.DepartmentService;

//此处注意要使用注解，这样才知道用到前面的service接口
@Service
public class DepartmentServiceImpl implements DepartmentService{
//这就是service接口实现类
	//注解注入dao,service调用dao，dao才是真正操作数据库的
	@Autowired
	private DepartmentDao departmentDao;
	@Autowired
	private AcademyDao academyDao;
	
	@Override
	public boolean add(Department department) {
		// TODO Auto-generated method stub
		return departmentDao.add(department);
	}
	@Override
	public List<Map<String, Object>> select(int page, int limit) {
		return departmentDao.select((page-1)*limit,limit);
	}
	@Override
	public boolean delete(int id) {
		boolean isSuccess;
		try {
			isSuccess = departmentDao.delete(id);
		} catch (Exception e) {
			return false;
		}
		//使用try,catch，捕获因操作带有外键约束的（而未添加外键约束的）数据时，反馈的异常，若成功，则返回true，失败返回false
		return isSuccess;
		//返回dao中delete的处理结果
	}
	@Override
	public boolean update(int id,String name,int aid){
		// TODO Auto-generated method stub
		return departmentDao.update(id,name,aid);
	}
	
	@Override
	public int getCount(){
		return departmentDao.getCount();
	}
	@Override
	public List<Academy> select() {
		// TODO Auto-generated method stub
		return academyDao.selectAll();
	}


}
	
	

